

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.io.Serializable;

public abstract class ShapeObject implements Serializable{

	public Point startingMousePosition;
	public boolean sobjSelected = false;
	public Point endingMousePosition;
	public Color color;
	
	public ShapeObject(Point startingMousePosition, Point endingMousePosition, Color color){
		
		this.startingMousePosition = startingMousePosition;
		this.endingMousePosition = endingMousePosition;
		this.color = color;
	}
	public void selectObject(DrawingCanvas canvas){
		Graphics iBGraphics = canvas.getImageBufferGraphics();
		   Color saveColor = iBGraphics.getColor( );
		   iBGraphics.setColor(Color.lightGray);
		   iBGraphics.drawRect(startingMousePosition.x-2, startingMousePosition.y-2, 
				   endingMousePosition.x-startingMousePosition.x+4,
				   endingMousePosition.y-startingMousePosition.y+4);
		   if(this.isResizeable()){
			   iBGraphics.fillRect(startingMousePosition.x,startingMousePosition.y,6,6);
			   iBGraphics.fillRect(endingMousePosition.x-5,endingMousePosition.y-5,6,6);
		   }
		   iBGraphics.setColor(saveColor);
		   canvas.repaint();
	}
	public void moveObject(int x, int y){
		this.endingMousePosition.x += x - this.startingMousePosition.x;
		this.endingMousePosition.y += y - this.startingMousePosition.y;
		this.startingMousePosition.x = x;
		this.startingMousePosition.y = y;
	}
	public void moveObject(Point p){
		moveObject(p.x, p.y);
	}
	public void resizeEndObject(Point p){
		if(isResizeable()){
			this.endingMousePosition = p;
		}
	}
	public void resizeStartObject(Point p){
		if(isResizeable()){
			this.startingMousePosition = p;
		}
	}
	public void setColor(Color c){
		this.color = c;
	}
	public boolean contains(int x, int y){
		if(startingMousePosition.x<x && endingMousePosition.x>x &&
				startingMousePosition.y<y && endingMousePosition.y>y){
			return true;
		}else{
			return false;
		}
	}
	public boolean contains(Point p){
		return contains(p.x, p.y);
	}
	public boolean resizeTopArea(Point p){
		if(this.isResizeable() && startingMousePosition.x + 6 >=p.x && startingMousePosition.y + 6 >= p.y){
			return true;
		}else{
			return false;
		}
	}
	public boolean resizeBottomArea(Point p){
		if(this.isResizeable() && endingMousePosition.x -6 <=p.x && endingMousePosition.y - 6 <= p.y){
			return true;
		}else{
			return false;
		}
	}
	public abstract boolean isResizeable();
	public abstract void drawShape(DrawingCanvas canvas);
	
}
